package com.sgb.kjwl.view.ui.adapter.shopping;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.goods.entity.GoodsSkuSelectResultEntity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.GoodsWebView;
import com.sgb.kjwl.model.entity.CallPhoneEntity;
import com.sgb.kjwl.model.entity.GoodsSkuDetailEntity;
import com.sgb.kjwl.model.entity.MaterialCompanyEntity;
import com.sgb.kjwl.model.entity.SkuCombinationEntity;
import com.sgb.kjwl.model.entity.user.RecommendListEntity;
import com.sgb.kjwl.model.entity.user.ServerAttrValue;
import com.sgb.kjwl.model.entity.user.SkuItemAttrEntity;
import com.sgb.kjwl.model.entity.website.GoodsParamDetailEntity;
import com.sgb.kjwl.utils.NumberFormatUtils;
import com.swgk.core.util.UiUtil;
import com.swgk.core.util.UserOperating;
import com.swgk.core.event.EventConstant;
import com.sgb.link.event.MaterialEvent;
import com.sgb.kjwl.view.event.RecyclerViewBannerNormal;
import com.sgb.kjwl.view.ui.activity.material.ConcreteDetailActivity2;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopGoodsDetailActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.swgk.core.util.DensityUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.apache.commons.lang3.StringEscapeUtils;
import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qiangHeNoooo
 * 说明：商品详情
 * 时间：2021.07.28
 */
public class GoodsDetailAdapter extends RecyclerView.Adapter {

    private final int TYPE_ONE = 1;
    private final int TYPE_TWO = 2;
    private final int TYPE_THREE = 3;
    private final int typeCount;
    private final Activity context;
    //    public final static long time = TimeUtils.getNowTime() + 1000 * 60 * 60 * 24 * 4;
    private GoodsSkuDetailEntity goodsSkuDetailEntity;
    private MaterialCompanyEntity materialCompanyEntity;
    private boolean userFocusStatus;
    private static int flagFocus;
    private List<SkuItemAttrEntity> skuItemAttrEntityList;
    private StringBuilder stringBuilder;
    private AttrAdapter attrAdapter;


    private GoodsSkuDetailEntity mGoodsSkuDetailEntity;
    private List<String> videoEntity;
    private List<RecommendListEntity> recommendListEntityList;
    private String platformStatementUrl;
    private boolean isSt;
    private static String superMoney = "0.00";
    private static long PromoteStartTime = 0;
    private static int promoteStatus;
    private static int priceType = 1;

    public GoodsDetailAdapter(Activity activity, int typeCount) {
        this.context = activity;
        this.typeCount = typeCount;
    }

    public GoodsDetailAdapter(Activity activity, int typeCount, Boolean isSt) {
        this.context = activity;
        this.typeCount = typeCount;
        this.isSt = isSt;
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        if (viewType == TYPE_ONE) {
            viewHolder = GoodsInfoViewHolder.get(context, parent, R.layout.item_goods_details_info);
        } else if (viewType == TYPE_TWO) {
            viewHolder = GoodsDetailsViewHolder.get(context, parent, R.layout.item_goods_details_details);
        } else if (viewType == TYPE_THREE) {
            viewHolder = GoodsCommendViewHolder.get(context, parent, R.layout.item_goods_details_recommend);
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof GoodsInfoViewHolder) {
            GoodsInfoViewHolder goodsInfoViewHolder = (GoodsInfoViewHolder) holder;
            goodsInfoViewHolder.initData(isSt);
            goodsInfoViewHolder.setGoodsInfoData(goodsSkuDetailEntity, isSt);
            goodsInfoViewHolder.setUserFocus(userFocusStatus);
            goodsInfoViewHolder.setCompanyInfo(materialCompanyEntity);
            goodsInfoViewHolder.setParamShopInfoData(skuItemAttrEntityList);
            goodsInfoViewHolder.setAttributeData(stringBuilder, attrAdapter);
        } else if (holder instanceof GoodsDetailsViewHolder) {
            GoodsDetailsViewHolder goodsDetailsViewHolder = (GoodsDetailsViewHolder) holder;
            goodsDetailsViewHolder.setGoodsDetails(mGoodsSkuDetailEntity);
            goodsDetailsViewHolder.setVideoParamData(videoEntity);
            goodsDetailsViewHolder.showPlatformStatementInfo(platformStatementUrl);
        } else if (holder instanceof GoodsCommendViewHolder) {
            GoodsCommendViewHolder goodsCommendViewHolder = (GoodsCommendViewHolder) holder;
            goodsCommendViewHolder.setGoodsRecommendAdapterData(recommendListEntityList);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_ONE;
        } else if (position == 1) {
            return TYPE_TWO;
        } else {
            return TYPE_THREE;
        }
    }

    @Override
    public int getItemCount() {
        return typeCount;
    }

    public void setGoodsInfo(GoodsSkuDetailEntity data) {
        goodsSkuDetailEntity = data;
    }

    public void showCompanyInfo(MaterialCompanyEntity data) {
        materialCompanyEntity = data;
    }

    public static String getSuperPrice() {
        return superMoney;
    }

    /**
     * 平台声明
     */
    public void showPlatformStatement(String platform) {
        platformStatementUrl = platform;
    }

    public void setUserFocusStatus(boolean data, int flag) {
        userFocusStatus = data;
        flagFocus = flag;
    }

    public void setParamShopInfo(List<SkuItemAttrEntity> sku) {
        skuItemAttrEntityList = sku;
    }

    public void setAttributes(StringBuilder info, AttrAdapter mAttrAdapter) {
        stringBuilder = info;
        attrAdapter = mAttrAdapter;
    }

    public void setAttributes(AttrAdapter mAttrAdapter) {
        attrAdapter = mAttrAdapter;
        notifyDataSetChanged();
    }

    /**
     * 参数信息和商品详情展示
     *
     * @param data 商品sku详情信息
     */
    public void setGoodsDetailsData(GoodsSkuDetailEntity data) {
        mGoodsSkuDetailEntity = data;
    }


    /**
     * 适配image和table标签
     */
    private static String setWebViewContent(String content) {
        String head = "<style type=\"text/css\"> img {" +
                "width:100%;" +//限定图片宽度填充屏幕
                "height:auto;" +//限定图片高度自动
                "}" +
                "body {" +
                "margin-right:15px;" +//限定网页中的文字右边距为15px(可根据实际需要进行行管屏幕适配操作)
                "margin-left:15px;" +//限定网页中的文字左边距为15px(可根据实际需要进行行管屏幕适配操作)
                "margin-top:15px;" +//限定网页中的文字上边距为15px(可根据实际需要进行行管屏幕适配操作)
                "font-size:38px;" +//限定网页中文字的大小为40px,请务必根据各种屏幕分辨率进行适配更改
                "word-wrap:break-word;" +//允许自动换行(汉字网页应该不需要这一属性,这个用来强制英文单词换行,类似于word/wps中的西文换行)
                "}" +
                "</style>";
        return "<html><header>" + head + "</header>" + content + "</html>";
    }

    public void initVideoParamData(List<String> video) {
        videoEntity = video;
    }


    public void setGoodsCommendData(List<RecommendListEntity> data) {
        recommendListEntityList = data;
    }

    public void setBannerAutoPlay(boolean b) {
//        goodsDetailsViewHolder.recyclerViewBannerNormal.setAutoPlaying(b);
    }

    /**
     * 设置弹框选中的回显
     */
    public void setPrice(GoodsSkuSelectResultEntity entity) {
        GoodsInfoViewHolder.setMoney(entity.money, entity.proMoney, entity.vipMoney, TextUtils.isEmpty(entity.promoteStart) ? 0 : Long.parseLong(entity.promoteStart), TextUtils.isEmpty(entity.promoteEnd) ? 0 : Long.parseLong(entity.promoteEnd), entity.type, entity.unit, entity.promoteStatus, entity.checkPosition);
    }

    public boolean getPromoteStatus() {
        return GoodsInfoViewHolder.isStartPromote();
    }

    public int getPriceType() {
        return priceType;
    }

    /**
     * 商品基础信息
     */
    static class GoodsInfoViewHolder extends RecyclerView.ViewHolder {
        static Context con;
        static TextView tvPrice;
        static TextView time_tx;
        static LinearLayout time_layout;
        static TextView day;//天
        static TextView tv_day;//天数
        static TextView tv_hours;//时
        static TextView tv_min;//分
        static TextView tv_seconds;//秒
        static ImageView shopType;//促销会员图片标识
        static TextView tvPrice2;//划线价
        static TextView tvPrice1;//会员&促销价
        static TextView time_tip;//会员提示语
        static TextView tvGoLogin;//去登录
        static LinearLayout vipLayout;//会员layout
        static LinearLayout priceLayout;//会员&促销价layout
        ImageView ivFocus;
        LinearLayout llFocus;
        TextView tvUserFocus;
        TextView tvTitle;
        ImageView ivZiYing;
        TextView tvQuotationTitle;
        TextView tvItemDescription;
        TextView tvRate;
        TextView tvBrandName;
        LinearLayout containerBrandName;
        TextView tvWarehousing;
        ImageView ivDitu;
        LinearLayout llDelivery;
        TextView tvDelivery;
        LinearLayout llShopInfo;
        TextView tvShopInfo;
        LinearLayout llGg;
        LinearLayout llSelect;
        RecyclerView recyclerView;
        ImageView ivShopImg;
        ImageView ivImageView;
        TextView tvShopName;
        TextView tvWebSite;
        TextView tvInvite;
        TextView tvJoin;
        GridView gridView;
        TextView tvComSettledInTime;
        TextView tvCallPhone;
        TextView tvEstablishmentDate;
        TextView tvComBusiness;
        TagFlowLayout tagOtherAttrContainer;

        TextView tvGuiGeTitle;
        TextView tvGuiGeContext;
        TextView tvBankingPayment;//网银支付

        public GoodsInfoViewHolder(Context context, @NonNull @NotNull View itemView) {
            super(itemView);
            con = context;
            tvPrice = itemView.findViewById(R.id.tv_price);
            time_layout = itemView.findViewById(R.id.timer_layout);
            day = itemView.findViewById(R.id.day);
            tv_day = itemView.findViewById(R.id.tv_day);
            tv_hours = itemView.findViewById(R.id.tv_hours);
            tv_min = itemView.findViewById(R.id.tv_minutes);
            tv_seconds = itemView.findViewById(R.id.tv_seconds);
            tvPrice2 = itemView.findViewById(R.id.tv_price_2);
            tvPrice1 = itemView.findViewById(R.id.tv_price_1);
            shopType = itemView.findViewById(R.id.img_type);
            time_tx = itemView.findViewById(R.id.time_tx);
            time_tip = itemView.findViewById(R.id.time_tip);
            tvGoLogin = itemView.findViewById(R.id.go_login);
            vipLayout = itemView.findViewById(R.id.vip_layout);
            priceLayout = itemView.findViewById(R.id.price_layout);
            llFocus = itemView.findViewById(R.id.ll_focus);
            if (context instanceof ConcreteDetailActivity2) {
                llFocus.setVisibility(View.INVISIBLE);
            } else {
                llFocus.setVisibility(View.VISIBLE);
                llFocus.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_FOCUS)));
            }
            ivFocus = itemView.findViewById(R.id.iv_focus);
            tvUserFocus = itemView.findViewById(R.id.tv_user_focus);
            tvTitle = itemView.findViewById(R.id.tv_title);
            ivZiYing = itemView.findViewById(R.id.image_ziying);
            tvItemDescription = itemView.findViewById(R.id.tv_item_description);
            tvQuotationTitle = itemView.findViewById(R.id.tv_quotation_time);
            tvRate = itemView.findViewById(R.id.tv_rate);
            containerBrandName = itemView.findViewById(R.id.container_brand_name);
            tvBrandName = itemView.findViewById(R.id.tv_brand_name);
            tvWarehousing = itemView.findViewById(R.id.tv_warehousing);
            ivDitu = itemView.findViewById(R.id.ditu);
            ivDitu.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_LOCATION)));
            llDelivery = itemView.findViewById(R.id.ll_deliveryTime);
            tvDelivery = itemView.findViewById(R.id.tv_delivery);
            llShopInfo = itemView.findViewById(R.id.ll_shop_info);
            tvShopInfo = itemView.findViewById(R.id.tv_shop_info);
            llGg = itemView.findViewById(R.id.rl_gg);
            llGg.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_SPECIFICATION)));
            llSelect = itemView.findViewById(R.id.ll_select);
            recyclerView = itemView.findViewById(R.id.rv_select);

            ivShopImg = itemView.findViewById(R.id.shop_img);
            ivImageView = itemView.findViewById(R.id.image_view);
            tvShopName = itemView.findViewById(R.id.shop_name);
            tvWebSite = itemView.findViewById(R.id.tv_web_site);
            tvWebSite.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_COMPANY)));
            tvInvite = itemView.findViewById(R.id.invite);
            tvInvite.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_INVITE)));
            tvJoin = itemView.findViewById(R.id.tv_join);
            tvJoin.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_JOIN)));
            gridView = itemView.findViewById(R.id.grid_view);
            tvComSettledInTime = itemView.findViewById(R.id.tv_com_settled_in_time);
            tvCallPhone = itemView.findViewById(R.id.tv_call_phone);
            tvCallPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_CALL_PHONE));

                }
            });
            tvEstablishmentDate = itemView.findViewById(R.id.tv_establishmentDate);
            tvComBusiness = itemView.findViewById(R.id.tv_com_business);

            tagOtherAttrContainer = itemView.findViewById(R.id.tag_container);
            tvGuiGeTitle = itemView.findViewById(R.id.tv_guise_title);
            tvGuiGeContext = itemView.findViewById(R.id.tv_guise_context);
            tvBankingPayment = itemView.findViewById(R.id.banking_payment);

        }

        public static GoodsInfoViewHolder get(Context context, ViewGroup viewGroup, int layoutId) {
            View itemView = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
            return new GoodsInfoViewHolder(context, itemView);
        }

        private void initData(boolean isSt) {
            if (isSt) {
                tvGuiGeTitle.setText("产品规格服务");
                tvGuiGeContext.setText("请选择规格及服务");
            } else {
                tvGuiGeTitle.setText("产品规格");
                tvGuiGeContext.setText("请选择规格");
            }
        }

        /**
         * 商品基本信息
         *
         * @param data 商品sku详情
         */
        @SuppressLint("SetTextI18n")
        private void setGoodsInfoData(GoodsSkuDetailEntity data, boolean isSt) {
            if (data == null) {
                return;
            }
//            data.isCompanyMember = "1";
//            for (int i = 0; i < data.getCheckedItemAttr().getList().size(); i++) {
//                data.getCheckedItemAttr().getList().get(i).setVipPrice("20.00");
//                data.getCheckedItemAttr().getList().get(i).setPromotePrice("30.00");
//                data.getCheckedItemAttr().getList().get(i).setPromoteStatus(2);
//            }
            if (isSt) {
                tvPrice.setVisibility(View.VISIBLE);
                if (data.getPrice().contains("元")) {
                    tvPrice.setText(data.getPrice());
                } else {
                    tvPrice.setText("¥" + data.getPrice() + "元/" + data.getUnit());
                }
            } else {
                int checkPosition = 0;
                if (data.getCheckedItemAttr() != null && data.getCheckedItemAttr().getList() != null) {
                    checkPosition = getCheckPosition(data);
                }
                SkuCombinationEntity entity = data.getCheckedItemAttr().getList().get(checkPosition);
                promoteStatus = entity.getPromoteStatus();
                long nowTime = System.currentTimeMillis();
                PromoteStartTime = Long.parseLong(TextUtils.isEmpty(entity.getPromoteStartTime()) ? "0" : entity.getPromoteStartTime());
                boolean isStartTime = (PromoteStartTime - nowTime) / 86400000 >= 3;
                boolean isEndTime = nowTime >= Long.parseLong(TextUtils.isEmpty(entity.getPromoteEndTime()) ? "0" : entity.getPromoteEndTime());
                //未登录
                if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0) == 0 && !UserOperating.getInstance().isLogged()) {
                    vipLayout.setVisibility(View.VISIBLE);
                    if (entity.getPromoteStatus() == 1) {
                        if (isStartTime) {
                            setTvPrice(data, checkPosition);
                        } else {
                            setTvPromotePrice(data, checkPosition);
                        }
                    } else if (entity.getPromoteStatus() == 2 && !isEndTime) {
                        setTvPromotePrice(data, checkPosition);
                    } else {
                        setTvPrice(data, checkPosition);
                    }
                } else {//已经登录
                    vipLayout.setVisibility(View.GONE);
                    tvPrice.setVisibility(View.GONE);
                    priceLayout.setVisibility(View.VISIBLE);
                    String vipPrice = entity.getVipPrice();
                    String proPrice = entity.getPromotePrice();
                    if (!TextUtils.isEmpty(vipPrice) && Double.valueOf(vipPrice) > 0) {
                        if (entity.getPromoteStatus() == 1) {
                            if (!isStartTime && Double.valueOf(vipPrice) > Double.valueOf(proPrice)) {//促销开始时间大于三天，不显示促销价
                                setTvPromotePrice(data, checkPosition);
                            } else {
                                setTvVipPrice(data, checkPosition);
                            }
                        } else if (entity.getPromoteStatus() == 2 && !isEndTime) {
                            if (Double.valueOf(vipPrice) > Double.valueOf(proPrice)) {
                                setTvPromotePrice(data, checkPosition);
                            } else {
                                setTvVipPrice(data, checkPosition);
                            }
                        } else {
                            setTvVipPrice(data, checkPosition);
                        }
                    } else if (!isStartTime && entity.getPromoteStatus() == 1) {
                        setTvPromotePrice(data, checkPosition);
                    } else if (entity.getPromoteStatus() == 2 && !isEndTime) {
                        setTvPromotePrice(data, checkPosition);
                    } else {
                        setTvPrice(data, checkPosition);
                    }
                }
            }

            if ("1".equals(data.getSelfSupportTag())) {
                ivZiYing.setVisibility(View.VISIBLE);
                tvTitle.setText("      " + data.getCartTitle());
            } else {
                ivZiYing.setVisibility(View.GONE);
                tvTitle.setText(data.getCartTitle());
            }
            tvQuotationTitle.setText(data.getUpdateTimeStr());
            if (!TextUtils.isEmpty(data.getItemDesc())) {
                tvItemDescription.setVisibility(View.VISIBLE);
                tvItemDescription.setText(data.getItemDesc());
            } else {
                tvItemDescription.setVisibility(View.GONE);
            }
            tvRate.setText(data.getTax());
            if (data.getBrandName() != null && !"".equals(data.getBrandName())) {
                containerBrandName.setVisibility(View.VISIBLE);
                tvBrandName.setText(data.getBrandName());
            } else {
                containerBrandName.setVisibility(View.GONE);
            }
            tvWarehousing.setText(data.getStorageName());
            llDelivery.setVisibility(data.commodityType != 0 ? View.VISIBLE : View.GONE);
            tvDelivery.setText(data.commodityType == 1 ? "现货" : (data.deliveryTimeUnit == 1 ? data.deliveryTime + "天" : data.deliveryTime + "个月"));
            setGoodsOtherService(data);
            tvBankingPayment.setVisibility("1".equals(data.isOpenAccount) ? View.VISIBLE : View.GONE);
            tvGoLogin.setOnClickListener(v -> VerificationCodeLoginActivity.start(con, EventConstant.EVENT_SHOP_GOODS_DETAIL_ACTIVITY_JUMP));
        }

        public static boolean isStartPromote() {
            if (promoteStatus == 1) {
                return true;
            }
            return false;
        }

        //设置原价
        private void setTvPrice(GoodsSkuDetailEntity data, int checkPosition) {
            priceType = 1;
            priceLayout.setVisibility(View.GONE);
            tvPrice.setVisibility(View.VISIBLE);
            time_layout.setVisibility(View.GONE);
            time_tip.setVisibility(View.GONE);
            time_tx.setVisibility(View.GONE);
            tvPrice.setText("¥" + NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(data.getCheckedItemAttr().getList().get(checkPosition).getMoney())) + "/" + data.getUnit());
        }

        //设置促销价
        private void setTvPromotePrice(GoodsSkuDetailEntity data, int checkPosition) {
            priceType = 2;
            tvPrice.setVisibility(View.GONE);
            priceLayout.setVisibility(View.VISIBLE);
            priceLayout.setBackgroundResource(R.mipmap.bg_cuxiao);
            shopType.setImageResource(R.mipmap.ic_cuxiaojia);
            String time2 = data.getCheckedItemAttr().getList().get(checkPosition).getPromoteEndTime();
            long endTime = Long.parseLong(TextUtils.isEmpty(time2) ? "0" : time2);
            UiUtil.startTimer(PromoteStartTime, endTime, time_tip, time_tx, time_layout, day, tv_day, tv_hours, tv_min, tv_seconds, data.getCheckedItemAttr().getList().get(checkPosition).getPromoteStatus(), checkPosition);
            tvPrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tvPrice2.setText("¥" + NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(data.getCheckedItemAttr().getList().get(checkPosition).getMoney())) + "/" + data.getUnit());
            tvPrice1.setText(NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(data.getCheckedItemAttr().getList().get(checkPosition).getPromotePrice())) + "/" + data.getUnit());
        }

        //设置会员价
        private void setTvVipPrice(GoodsSkuDetailEntity data, int checkPosition) {
            priceType = 3;
            shopType.setImageResource(R.mipmap.ic_huiyuanjia);
            priceLayout.setBackgroundResource(R.mipmap.bg_vip);
            time_tip.setVisibility(View.GONE);
            time_tx.setVisibility(View.GONE);
            time_layout.setVisibility(View.GONE);
            tvPrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tvPrice2.setText("¥" + NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(data.getCheckedItemAttr().getList().get(checkPosition).getMoney())) + "/" + data.getUnit());
            tvPrice1.setText(NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(data.getCheckedItemAttr().getList().get(checkPosition).getVipPrice())) + "/" + data.getUnit());
        }

        /**
         * 设置商品价格
         *
         * @param price 商品价格
         */
        public static void setMoney(String price, String promotePrice, String vipPrice, long startTime, long endTime, int selectType, String unit, int status, int position) {
            priceType = selectType;
            promoteStatus = status;
            if (selectType == 1) {
                priceLayout.setVisibility(View.GONE);
                tvPrice.setVisibility(View.VISIBLE);
                tvPrice.setText("¥" + NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(price)) + "/" + unit);
            } else if (selectType == 2) {
                tvPrice.setVisibility(View.GONE);
                priceLayout.setVisibility(View.VISIBLE);
                tvPrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                shopType.setImageResource(R.mipmap.ic_cuxiaojia);
                PromoteStartTime = startTime;
                UiUtil.startTimer(startTime, endTime, time_tip, time_tx, time_layout, day, tv_day, tv_hours, tv_min, tv_seconds, status, position);
                tvPrice1.setText(NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(promotePrice)) + "/" + unit);
            } else {
                tvPrice.setVisibility(View.GONE);
                priceLayout.setVisibility(View.VISIBLE);
                tvPrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                shopType.setImageResource(R.mipmap.ic_huiyuanjia);
                time_tip.setVisibility(View.GONE);
                time_tx.setVisibility(View.GONE);
                time_layout.setVisibility(View.GONE);
                tvPrice1.setText(NumberFormatUtils.formatAmtNoUseGroup(Float.valueOf(vipPrice)) + "/" + unit);
            }
        }

        /**
         * 获取默认选择的sku checkList的position
         *
         * @param data
         * @return
         */
        public int getCheckPosition(GoodsSkuDetailEntity data) {
            for (int i = 0; i < data.getCheckedItemAttr().getList().size(); i++) {
                int num = 0;
                for (int j = 0; j < data.getCheckedItemAttr().getList().get(i).getList().size(); j++) {
                    for (int k = 0; k < data.getItemAttr().getCheck().size(); k++) {
                        if (data.getItemAttr().getCheck().get(k).getValId().equals(String.valueOf(data.getCheckedItemAttr().getList().get(i).getList().get(j).getValId()))) {
                            num++;
                        }
                        if (num == data.getCheckedItemAttr().getList().get(i).getList().size()) {
                            return i;
                        }
                    }
                }

            }
            return 0;
        }

        private void setUserFocus(boolean data) {
            if (data) {
                Drawable drawable = ContextCompat.getDrawable(con, R.mipmap.icon_follow_red);
                ivFocus.setImageDrawable(drawable);
                tvUserFocus.setText("已关注");
                tvUserFocus.setTextColor(ContextCompat.getColor(con, R.color.color_main));
                if (flagFocus == 1) {
                    MToast.showToast(con, "关注成功");
                    flagFocus = 0;
                }
            } else {
                Drawable drawable = ContextCompat.getDrawable(con, R.mipmap.icon_follow_gray);
                ivFocus.setImageDrawable(drawable);
                tvUserFocus.setText("关注");
                tvUserFocus.setTextColor(ContextCompat.getColor(con, R.color.color_666666));
                if (flagFocus == 1) {
                    MToast.showToast(con, "取消关注");
                    flagFocus = 0;
                }
            }
        }

        private void setCompanyInfo(MaterialCompanyEntity data) {
            if (data == null) {
                return;
            }
            if (!isDestroy()) {
                RequestOptions options = new RequestOptions()
                        .placeholder(R.mipmap.shop_img_new_2)
                        .error(R.mipmap.shop_img_new_2);
                Glide.with(con)
                        .load(data.getCompanyLogo())
                        .apply(options)
                        .transform(new GlideRoundTransform(con, 5, "#f5f5f5", 1))
                        .into(ivShopImg);
            }

            if ("1".equals(data.getSelfSupportTag())) {
                ivImageView.setVisibility(View.VISIBLE);
            } else {
                ivImageView.setVisibility(View.GONE);
            }
            tvShopName.setText(data.getCompanyName());
            GridViewAdapter gridViewAdapter = new GridViewAdapter(con, R.layout.goods_detail_grid_item, data.getGoodsList());
            gridViewAdapter.setOnItemClick(goodsListBean -> {
                if ("0".equals(goodsListBean.getType())) {
                    ShopGoodsDetailActivity.start(con, goodsListBean.getItemId(), "", goodsListBean.getSkuId());
                } else {
                    ConcreteDetailActivity2.start(con, goodsListBean.getItemId());
                }
            });
            gridView.setAdapter(gridViewAdapter);
            SpanUtils.with(tvCallPhone).append(data.getPhone()).setForegroundColor(ColorUtils.getColor(R.color.color_5792FD)).append("  ").appendImage(R.mipmap.goods_call_phone).create();
            tvComSettledInTime.setText(data.getConcat());
            tvEstablishmentDate.setText(data.getEstablishmentDate());
            tvComBusiness.setText(data.getBusiness());
        }

        private boolean isDestroy() {
            return con == null || ((Activity) con).isFinishing() || ((Activity) con).isDestroyed();
        }

        private void setParamShopInfoData(List<SkuItemAttrEntity> sku) {
            if (sku == null) {
                return;
            }
            llShopInfo.setVisibility(sku.size() == 0 ? View.GONE : View.VISIBLE);
            llSelect.setVisibility(sku.size() == 0 ? View.GONE : View.VISIBLE);

        }

        private void setAttributeData(StringBuilder info, AttrAdapter mAttrAdapter) {
            if (info == null || mAttrAdapter == null) {
                return;
            }
            tvShopInfo.setText(info.substring(0, info.length() - 1));
            llShopInfo.setOnClickListener(v -> EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_PARAM)));
            recyclerView.setLayoutManager(new LinearLayoutManager(UiUtil.getContext(), RecyclerView.HORIZONTAL, false));
            recyclerView.setAdapter(mAttrAdapter);
        }

        /**
         * 商品其他服务
         *
         * @param data
         */
        private void setGoodsOtherService(GoodsSkuDetailEntity data) {
            List<ServerAttrValue> itemServerAttrVals = data.getItemServerAttrVals();
            if (itemServerAttrVals == null || itemServerAttrVals.size() == 0) {
                return;
            }
            for (ServerAttrValue attrValue : itemServerAttrVals) {
                if (attrValue.getServiceType() == 1) {
                    List<ServerAttrValue.GoodsServiceOtherAttr> attrValueValue = attrValue.getValue();
                    if (attrValueValue != null && attrValueValue.size() != 0) {
                        setGoodsOtherService(attrValueValue);
                    }
                    break;
                }
            }
        }

        private void setGoodsOtherService(List<ServerAttrValue.GoodsServiceOtherAttr> attrList) {
            List<ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue> attrValueArrayList = new ArrayList<>();
            for (ServerAttrValue.GoodsServiceOtherAttr otherAttrValue : attrList) {
                List<ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue> otherAttrValueValue = otherAttrValue.getValue();
                if (otherAttrValueValue != null && otherAttrValueValue.size() != 0) {
                    for (ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue oav : otherAttrValueValue) {
                        if (oav.getChecked() == 1) {
                            attrValueArrayList.add(oav);
                        }
                    }
                }
            }
            if (attrValueArrayList.size() > 0) {
                tagOtherAttrContainer.setVisibility(View.VISIBLE);
                showGoodsOtherService(attrValueArrayList);
            }
        }

        private void showGoodsOtherService(List<ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue> attrValueArrayList) {
            TagAdapter<ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue> attrAdapter = new TagAdapter<ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue>(attrValueArrayList) {
                @Override
                public View getView(com.zhy.view.flowlayout.FlowLayout parent, int position, ServerAttrValue.GoodsServiceOtherAttr.OtherAttrValue otherAttrValue) {
                    final LayoutInflater mInflater = LayoutInflater.from(con);
                    LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.item_goods_service_other, tagOtherAttrContainer, false);
                    TextView tv = layout.findViewById(R.id.item_attr);
                    tv.setText(otherAttrValue.getAttributeName());
                    return layout;
                }
            };
            tagOtherAttrContainer.setAdapter(attrAdapter);
        }
    }


    /**
     * 商品详情
     */
    static class GoodsDetailsViewHolder extends RecyclerView.ViewHolder {
        Context con;
        LinearLayout detailsContainer;
        RecyclerView recParam;
        LinearLayout itemDetailContainer;
        FrameLayout flVideo;
        RecyclerViewBannerNormal recyclerViewBannerNormal;
        TextView tvPos;
        TextView tvSum;
        LinearLayout llWv;
        LinearLayout llWw;
        LinearLayout platformStatementContainer;
        LinearLayout llPlatformStatement;
        boolean isShowDetail = false;
        boolean isTitleDetail = false;
        boolean showPlatformStatement = false;

        public GoodsDetailsViewHolder(Context context, @NonNull @NotNull View itemView) {
            super(itemView);
            con = context;
            detailsContainer = itemView.findViewById(R.id.details_container);
            recParam = itemView.findViewById(R.id.rec_param);
            itemDetailContainer = itemView.findViewById(R.id.item_details_container);
            flVideo = itemView.findViewById(R.id.fl_video);
            recyclerViewBannerNormal = itemView.findViewById(R.id.banner_video);
            tvPos = itemView.findViewById(R.id.tv_pos);
            tvSum = itemView.findViewById(R.id.tv_sum);
            llWv = itemView.findViewById(R.id.ll_wv);
            llWw = itemView.findViewById(R.id.ll_ww);
            platformStatementContainer = itemView.findViewById(R.id.platform_statement_container);
            llPlatformStatement = itemView.findViewById(R.id.ll_platform_statement);
        }

        public static GoodsDetailsViewHolder get(Context context, ViewGroup viewGroup, int layoutId) {
            View itemView = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
            return new GoodsDetailsViewHolder(context, itemView);
        }

        @SuppressLint("SetJavaScriptEnabled")
        private void setGoodsDetails(GoodsSkuDetailEntity data) {
            if (data == null) {
                detailsContainer.setVisibility(View.GONE);
                return;
            } else {
                detailsContainer.setVisibility(View.VISIBLE);
            }
            List<GoodsParamDetailEntity> detailEntities = new ArrayList<>();
            if (data.getCartTitle() != null && !"".equals(data.getCartTitle())) {
                detailEntities.add(new GoodsParamDetailEntity("品名", data.getCartTitle()));
            }
            if (data.getUnit() != null && !"".equals(data.getUnit())) {
                detailEntities.add(new GoodsParamDetailEntity("计量单位", data.getUnit()));
            }
            if (data.getBrandName() != null && !"".equals(data.getBrandName())) {
                detailEntities.add(new GoodsParamDetailEntity("品牌", data.getBrandName()));
            }
            if (data.getStorageName() != null && !"".equals(data.getStorageName())) {
                detailEntities.add(new GoodsParamDetailEntity("仓储", data.getStorageName()));
            }
            if (data.getTax() != null && !"".equals(data.getTax())) {
                detailEntities.add(new GoodsParamDetailEntity("税率", data.getTax()));
            }
            List<GoodsSkuDetailEntity.Params> dataParams = data.getParams();
            if (dataParams != null && dataParams.size() != 0) {
                for (GoodsSkuDetailEntity.Params params : dataParams) {
                    detailEntities.add(new GoodsParamDetailEntity(params.k, params.v));
                }
            }
            if (detailEntities.size() != 0) {
                recParam.setLayoutManager(new LinearLayoutManager(con));
                GoodsParamAdapter goodsParamAdapter = new GoodsParamAdapter(con, detailEntities);
                recParam.setAdapter(goodsParamAdapter);
            } else {
                recParam.setVisibility(View.GONE);
            }
            if (!TextUtils.isEmpty(data.getItemDetail())) {
                if (isShowDetail) {
                    return;
                }
                if (llWv.getChildCount() != 0) {
                    llWv.removeAllViews();
                }
                isShowDetail = true;
                WebView webView1 = new WebView(con);
                WebSettings webSettings = webView1.getSettings();
                webSettings.setUseWideViewPort(true);
                webSettings.setLoadWithOverviewMode(true);
                webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
                llWv.setVisibility(View.VISIBLE);
                webView1.setHorizontalScrollBarEnabled(false);
                webView1.setVerticalScrollBarEnabled(false);
                webView1.loadDataWithBaseURL(null, setWebViewContent(data.getItemDetail()), "text/html", "UTF-8", null);
//            webView1.setWebViewClient(new WebViewClient() {
//                @Override
//                public void onPageFinished(WebView view, String url) {
//                    new Handler().postDelayed(() -> {
//                        webView1.measure(0, 0);
//                        int measuredHeight = webView1.getMeasuredHeight();
//                        ViewGroup.LayoutParams layoutParams = webView1.getLayoutParams();
//                        layoutParams.height = measuredHeight;
//                        webView1.setLayoutParams(layoutParams);
//                    }, 1000);
//                }
//            });
                webView1.requestLayout();
                llWv.addView(webView1);
                webView1.requestLayout();
            } else {
                llWv.setVisibility(View.GONE);
            }
            final String itemTitleUrl = data.getItemTitleUrl();
            if (!TextUtils.isEmpty(itemTitleUrl)) {

                if (isTitleDetail) {
                    return;
                }
                if (llWw.getChildCount() != 0) {
                    llWw.removeAllViews();
                }
                isTitleDetail = true;
                WebView webView2 = new WebView(con);
                webView2.setFocusable(true);
                webView2.setFocusableInTouchMode(true);
                WebSettings webSettings = webView2.getSettings();
                webSettings.setJavaScriptEnabled(true);
                webSettings.setDomStorageEnabled(true);
                webSettings.setAppCacheEnabled(false);
                llWw.setVisibility(View.VISIBLE);
                webView2.loadUrl(StringEscapeUtils.unescapeJava(itemTitleUrl));
                webView2.requestLayout();
                llWw.addView(webView2);
                webView2.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return super.shouldOverrideUrlLoading(view, url);
                    }

//                @Override
//                public void onPageFinished(WebView view, String url) {
//                    new Handler().postDelayed(() -> {
//                        webView2.measure(0, 0);
//                        int measuredHeight = webView2.getMeasuredHeight();
//                        ViewGroup.LayoutParams layoutParams = webView2.getLayoutParams();
//                        layoutParams.height = measuredHeight;
//                        webView2.setLayoutParams(layoutParams);
//                    }, 1000);
//                }
                });
                webView2.requestLayout();
            } else {
                llWw.setVisibility(View.GONE);
            }
            if (flVideo.getVisibility() == View.GONE && llWv.getVisibility() == View.GONE) {
                itemDetailContainer.setVisibility(View.GONE);
                if (recParam.getVisibility() == View.VISIBLE) {
                    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) recParam.getLayoutParams();
                    layoutParams.setMargins(0, 0, 0, DensityUtils.dip2px(con, 12));
                    recParam.setLayoutParams(layoutParams);
                }
            }
        }

        private void setVideoParamData(List<String> video) {
            if (video == null || video.size() == 0) {
                return;
            }
            itemDetailContainer.setVisibility(View.VISIBLE);
            flVideo.setVisibility(View.VISIBLE);
            tvPos.setText("1");
            tvSum.setText(String.valueOf(video.size()));
            recyclerViewBannerNormal.initBannerImageView(video, true, true, 1);
            recyclerViewBannerNormal.setIndicatorInterval(3000);
            recyclerViewBannerNormal.onSel(index -> tvPos.setText(String.valueOf((index % video.size()) + 1)));
        }

        @SuppressLint("SetJavaScriptEnabled")
        private void showPlatformStatementInfo(String platformStatementUrl) {
            if (!TextUtils.isEmpty(platformStatementUrl)) {
                if (showPlatformStatement) {
                    return;
                }
                showPlatformStatement = true;
                platformStatementContainer.setVisibility(View.VISIBLE);
                GoodsWebView.removeView();
                if (GoodsWebView.web != null) {
                    GoodsWebView.web.loadUrl(platformStatementUrl);
                    llPlatformStatement.addView(GoodsWebView.web);
                }
            } else {
                platformStatementContainer.setVisibility(View.GONE);
            }

        }

    }

    /**
     * 商品推荐
     */
    static class GoodsCommendViewHolder extends RecyclerView.ViewHolder {
        Context con;
        LinearLayout recommendContainer;
        RecyclerView receiveRecommend;


        public GoodsCommendViewHolder(Context context, @NonNull @NotNull View itemView) {
            super(itemView);
            recommendContainer = itemView.findViewById(R.id.recommend_container);
            receiveRecommend = itemView.findViewById(R.id.receive_recommend);
            con = context;
        }

        public void setGoodsRecommendAdapterData(List<RecommendListEntity> data) {
            if (data == null || data.size() == 0) {
                recommendContainer.setVisibility(View.GONE);
                return;
            } else {
                recommendContainer.setVisibility(View.VISIBLE);
            }
            receiveRecommend.setLayoutManager(new GridLayoutManager(con, 2));
            GoodsRecommendAdapter goodsRecommendAdapter = new GoodsRecommendAdapter(con, data);
            goodsRecommendAdapter.setResembleGoodsClick(recommendListEntity -> {
                if ("7".equals(recommendListEntity.getCid())) {
                    MLog.i(">>>>>>>>>>>>>>", "商砼，我被点击了");
                    ConcreteDetailActivity2.start(con, recommendListEntity.getId());
                } else {
                    MLog.i(">>>>>>>>>>>>>>", "商品，我被点击了");
                    ShopGoodsDetailActivity.start(con, recommendListEntity.getId(), "", recommendListEntity.getSkuid());
                }
//                EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_GOODS_DETAILS_JUMP).setMessageData(recommendListEntity));
            });
            receiveRecommend.setAdapter(goodsRecommendAdapter);
            goodsRecommendAdapter.notifyDataSetChanged();
        }


        public static GoodsCommendViewHolder get(Context context, ViewGroup viewGroup, int layoutId) {
            View itemView = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
            return new GoodsCommendViewHolder(context, itemView);
        }
    }

}
